package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.Teachplan;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "课程计划编辑接口")
public class TeachplanController {

    @Resource
    TeachplanService teachplanService;

    @GetMapping("/teachplan/{courseId}/tree-nodes")
    @ApiOperation("查询课程计划树形结构")//添加课程后会自动跳到这个章,基本信息后的课程大纲
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")//用是否传递课程ID来判断时修改还是新增章节 todo 以后像这样以是否传递主键来判断增改很常见
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto){
        teachplanService.saveTeachplan(saveTeachplanDto);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachplan(@PathVariable Long id){
        teachplanService.deleteTeachplan(id);
    }

    @ApiOperation("课程计划排序上移动")
    @PostMapping("/teachplan/moveup/{id}")
    public void upOrderby(@PathVariable Long id){
        teachplanService.upOrderby(id);
    }

    @ApiOperation("课程计划排序下移动")
    @PostMapping("/teachplan/movedown/{id}")
    public void downOrderby(@PathVariable Long id){
        teachplanService.downOrderby(id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

//通过课程计划ID,来查询课程计划是否免费,专门的远程调用接口
    @RequestMapping("/teachplan/isFree")
    public Teachplan getTeachplanisFree(Long teachplanId){
        return teachplanService.getTeachplanisFree(teachplanId);
    }
}
